package com.example.lightenergypolymerize.controller;

import com.example.lightenergypolymerize.entity.Comment;
import com.example.lightenergypolymerize.service.ICommentService;
import com.example.lightenergypolymerize.util.ResponseEntity;
import com.example.lightenergypolymerize.util.SecurityUtil;
import com.example.lightenergypolymerize.util.idempotent.Idempotent;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/comment")
public class CommentController {
    @Resource
    private ICommentService commentService;
    @RequestMapping("/add")
    @Idempotent
    public ResponseEntity add(@Validated Comment comment) {
        comment.setUid(SecurityUtil.getCurrentUser().getUid());
        boolean result = commentService.save(comment);
        if(result) {
            return ResponseEntity.succ(result);
        }
        return ResponseEntity.fail("添加失败，请重试！！");
    }
}
